/**
 * 模态框
 */
module.exports = function ($scope, $state, $stateParams,$resource,$modal) {
	/* 分页
     * ========================================= */
    $scope.maxSize = 5;             //最多显示多少个按钮
    $scope.currentPage = 1;      //当前页码
    $scope.itemsPerPage = 10         //每页显示几条
	


	$scope.pageChanged = function () {
       var para = {
            pageNo:$scope.currentPage,
            pageSize:$scope.itemsPerPage,

            
        };
		

		$resource('/api/as/dsc/supply/findInfoList', {}, {}).
			save(para, function(res){			                
                if(res.errcode === 0 || res.errcode === 10003){
					console.log(res);
					$scope.objs=res.data.results;									
					$scope.totalItems = res.data.totalRecord;

                }else{
                    alert(res.errmsg);
                }
            });

    };
	$scope.pageChanged();


			$scope.search=function(){
			var dic = {
				pageNo:$scope.currentPage,
            	pageSize:$scope.itemsPerPage,
				
			}
				
				$resource('', {}, {}).save(dic, function(res){
                if(res.errcode === 0 || res.errcode === 10003){
                    // console.log(res);
					$scope.objs=res.data.results;
                    $scope.totalItems = res.data.totalRecord;
                }else{
                    alert(res.errmsg);
                }
            });
			}

			$scope.up= function (index) {    
				console.log($scope.objs[index].project_code) ;          
				 if(confirm('确认上线？')){
					$resource('/api/ac/dsc/supplyService/updateUp', {}, {}).save({'order_code':$scope.objs[index].order_code}, function(res){			              
                if(res.errcode === 0 || res.errcode === 10003){
						alert('上线成功')			
						$scope.pageChanged();
                }else{
                    alert(res.errmsg);
                }
            });				
				 }					 
			}

			$scope.down= function (index) {    
				console.log($scope.objs[index].project_code) ;          
				 if(confirm('确认下线？')){
					$resource('/api/ac/dsc/supplyService/updateDown', {}, {}).save({'order_code':$scope.objs[index].order_code}, function(res){			              
                if(res.errcode === 0 || res.errcode === 10003){
						alert('下线成功')			
						$scope.pageChanged();
                }else{
                    alert(res.errmsg);
                }
            });				
				 }					 
			}

            $scope.toinfo= function (index) {
                 $scope.item = $scope.objs[index];
                console.log($scope.objs[index]);							
				var modalInstance = $modal.open({
					template: require('../views/order_info.html'),
					controller: 'order_info',
					size: 'lg',
					resolve: {
						 items: function () {
						 	return $scope.item;
						 }
					}
				});
				modalInstance.result.then(function (showResult) {	
						$scope.pageChanged();
				});
			}

			$scope.modify= function (index) {
                 $scope.item = $scope.objs[index];
                console.log($scope.objs[index]);							
				var modalInstance = $modal.open({
					template: require('../views/hy_order_modify.html'),
					controller: 'hy_order_modify',
					size: 'lg',
					resolve: {
						 items: function () {
						 	return $scope.item;
						 }
					}
				});
				modalInstance.result.then(function (showResult) {	
						$scope.pageChanged();
				});
			}

}